package com.cpr.ams.util;

import lombok.Data;

import java.io.Serializable;

/**
 * 自定义响应结构类
 */
@Data
public class Result<T> implements Serializable {

    private Integer code;
    private String message;
    private Long time;
    private T data;

    private Result(StatusCode statusCode, T data) {
        this.code = statusCode.getCode();
        this.message = statusCode.getMessage();
        this.time = System.currentTimeMillis();
        this.data = data;
    }

    private Result(StatusCode statusCode) {
        this(statusCode,null);
    }

    public static Result success() {
        return new Result(StatusCode.SUCCESS);
    }

    public static <E> Result success(E data) {
        return new Result<>(StatusCode.SUCCESS,data);
    }

    public static Result fail(StatusCode statusCode) {
        return new Result(statusCode);
    }

    public static <F> Result fail(StatusCode statusCode,F data) {
        return new Result<>(statusCode,data);
    }
}